package com.vayne.lifecycle;

import com.vayne.bean.Category;
import com.vayne.bean.Course;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

/**
 * @author xuerui.zhang
 * @since 2020/4/17 下午3:12
 */
public class MergeBeanDefinitionDemo {

    // org.springframework.beans.factory.config.ConfigurableBeanFactory.getMergedBeanDefinition
    // org.springframework.beans.factory.config.BeanDefinition.getParentName
    // org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(java.lang.String)
    public static void main(String[] args) {
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader beanDefinition = new XmlBeanDefinitionReader(beanFactory);
        String path = "classpath:/dependency_lookup_config.xml";
        beanDefinition.loadBeanDefinitions(path);

        // parent 不需要 merge：RootBeanDefinition
        Course course = beanFactory.getBean("course", Course.class);
        System.out.println("[Course]：" + course);

        // 普通的需要 merge
        Course category = beanFactory.getBean("category", Category.class);
        System.out.println("[Category]：" + category);
    }
}
